<template>
  <div class="my-page bg-c2">
    <div class="myheaderbox">
      <div class="headerlogo">
        <img src="../../assets/img/photo.png">
      </div>
      <h5 id="nick_name" class="fs22 c1">{{mydata.nickName}}</h5>
      <h2 id="user_name">{{mydata.userName}}</h2>
    </div>
    <div class="mycontentbox">
      <div class="contentbox-item">
        <div class="mycontent_head">
          <p>RNB资产</p>
          <span @click="doWithdraw(0)" class="c3">提现</span>
        </div>
        <div class="ul-wrap">
          <ul>
            <li>
              <h3>锁仓数量</h3>
              <p id="integral">{{gicData.integral || 0 |twoFloat}}</p>
            </li>
            <li>
              <h3>可提数量</h3>
              <p id="can_extract_amount">{{gicData.canExtractAmount || 0 |twoFloat}}</p>
            </li>
            <li>
              <h3>已提数量</h3>
              <p id="withdraw_amount">{{gicData.withdrawAmount || 0 |twoFloat}}</p>
            </li>
            <li>
              <h3>当日交易量</h3>
              <p id="integral">{{0 || 0 |twoFloat}}</p>
            </li>
            <li>
              <h3>释放</h3>
              <p id="can_extract_amount">{{0 || 0 |twoFloat}}</p>
            </li>
            <li>
              <h3>状态</h3>
              <p id="withdraw_amount">...</p>
            </li>
          </ul>
        </div>
      </div>

      <div class="contentbox-item">
        <div class="mycontent_head">
          <p>RNBX资产</p>
          <span @click="doWithdraw(2)" class="c3">提现</span>
        </div>
        <div class="ul-wrap">
          <ul>
            <li>
              <h3>锁仓数量</h3>
              <p id="integral">{{rnbxData.integral|| 0 |twoFloat}}</p>
            </li>
            <li>
              <h3>可提数量</h3>
              <p id="can_extract_amount">{{rnbxData.canExtractAmount || 0 |twoFloat}}</p>
            </li>
            <li>
              <h3>已提数量</h3>
              <p id="withdraw_amount">{{rnbxData.withdrawAmount|| 0 |twoFloat}}</p>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="quit-wrap">
      <button class="quitbtn" @click="logout()">安全退出</button>
    </div>
  </div>
</template>

<script>
import * as z from "@/utils/com.js";
import * as r from "@/utils/validate.js";
export default {
  created() {
    this.mydata = JSON.parse(this.$auth.get()["localdata"]);
    this.getReleaseData();
    this.getGicData();
  },
  data() {
    return {
      mydata: {},
      gicData: {},
      rnbxData: {}, //rnbx
      release: [{}, {}, {}, {}]
    };
  },
  methods: {
    doWithdraw(kindId) {
      console.log(kindId);
      z.prompt("请输入您需要提现的数量", async val => {
        if (!r.validatNum(val.value)) {
          z.alert("请输入数字");
          return;
        }
        if (val.value <= "0") {
          z.alert("不能小于0");
          return;
        }
        let response = await this.$http.post(
          "/bus/withdraw/do",
          this.$qs.stringify({
            userId: JSON.parse(localStorage.getItem("localdata")).uuid,
            amount: val.value,
            withdrawType: kindId
          })
        );
        z.alert(response.data.msg);
      });
    },

    logout() {
      this.$auth.logout();
      window.location.href = "/auth/login/logout";
    },

    async getReleaseData() {
      let response = await this.$http.post(
        "/sys/partner/parreport",
        this.$qs.stringify({
          userId: this.mydata.uuid
        })
      );
      if (200 == response.data.code) {
        this.release = response.data.data;
      } else {
        z.alert(response.data.msg);
      }
    },
    async getGicData() {
      let gicRes = await this.$http.post(
        "/bus/account/get",
        this.$qs.stringify({
          userId: this.mydata.uuid
        })
      );
      if (200 == gicRes.data.code) {
        for (let i in gicRes.data.data) {
          //根据amountType判断是哪个币种的信息
          if (gicRes.data.data[i].amountType == 0) {
            this.gicData = gicRes.data.data[i];
          } else if (gicRes.data.data[i].amountType == 2) {
            this.rnbxData = gicRes.data.data[i];
          }
        }
      } else {
        z.alert(gicRes.data.msg);
      }
    }
  },

  mounted() {
    setInterval(val => {
      this.getGicData();
    }, 20000);
  }
};
</script>
<style lang="scss" scope src="./styles/index.scss">
</style>

